package com.dynamixsoftware.printershare.bt;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Looper;
import com.dynamixsoftware.printershare.App;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.UUID;

class BTAdapterImpl20
  extends BTAdapter
{
  private Object ba;
  private Method ba_cancelDiscovery;
  private Method ba_getRemoteDevice;
  private Method ba_isDiscovering;
  private Method ba_isEnabled;
  private Method ba_startDiscovery;
  private Method bc_getDeviceClass;
  private Class<?> bcc;
  private Field bd_BOND_BONDED;
  private Method bd_createBond;
  private Method bd_createInsecureRfcommSocket;
  private Method bd_createInsecureRfcommSocketToServiceRecord;
  private Method bd_createRfcommSocket;
  private Method bd_createRfcommSocketToServiceRecord;
  private Method bd_getAddress;
  private Method bd_getAliasName;
  private Method bd_getBluetoothClass;
  private Method bd_getBondState;
  private Method bd_getName;
  private Method bd_getServiceChannel;
  private Class<?> bdc;
  private Method bs_close;
  private Method bs_connect;
  private Method bs_getInputStream;
  private Method bs_getOutputStream;
  private Class<?> bsc;
  
  private BTAdapterImpl20(Object paramObject)
    throws Exception
  {
    this.ba = paramObject;
    Class localClass1 = paramObject.getClass();
    this.ba_isEnabled = localClass1.getMethod("isEnabled", new Class[0]);
    this.ba_isDiscovering = localClass1.getMethod("isDiscovering", new Class[0]);
    this.ba_startDiscovery = localClass1.getMethod("startDiscovery", new Class[0]);
    this.ba_cancelDiscovery = localClass1.getMethod("cancelDiscovery", new Class[0]);
    this.ba_getRemoteDevice = localClass1.getMethod("getRemoteDevice", new Class[] { String.class });
    this.bdc = Class.forName("android.bluetooth.BluetoothDevice");
    this.bd_BOND_BONDED = this.bdc.getField("BOND_BONDED");
    this.bd_getAddress = this.bdc.getMethod("getAddress", new Class[0]);
    this.bd_getName = this.bdc.getMethod("getName", new Class[0]);
    try
    {
    	try {
            this.bd_getAliasName = this.bdc.getMethod("getAliasName", new Class[0]);
         } catch (NoSuchMethodException var16) {
            ;
         }
      this.bd_getBluetoothClass = this.bdc.getMethod("getBluetoothClass", new Class[0]);
      this.bd_getBondState = this.bdc.getMethod("getBondState", new Class[0]);
      this.bd_createBond = this.bdc.getMethod("createBond", new Class[0]);
      Class localClass2 = this.bdc;
      Class[] arrayOfClass1 = new Class[1];
      arrayOfClass1[0] = Integer.TYPE;
      this.bd_createRfcommSocket = localClass2.getMethod("createRfcommSocket", arrayOfClass1);
      Class localClass3 = this.bdc;
      Class[] arrayOfClass2 = new Class[1];
      arrayOfClass2[0] = Integer.TYPE;
      this.bd_createInsecureRfcommSocket = localClass3.getMethod("createInsecureRfcommSocket", arrayOfClass2);
      this.bd_createRfcommSocketToServiceRecord = this.bdc.getMethod("createRfcommSocketToServiceRecord", new Class[] { UUID.class });
      try
      {
        this.bd_createInsecureRfcommSocketToServiceRecord = this.bdc.getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class });
        try
        {
//          label321:
          Class localClass4 = this.bdc;
          Class[] arrayOfClass3 = new Class[1];
          arrayOfClass3[0] = Class.forName("android.os.ParcelUuid");
          this.bd_getServiceChannel = localClass4.getMethod("getServiceChannel", arrayOfClass3);
          label355:
          this.bcc = Class.forName("android.bluetooth.BluetoothClass");
          this.bc_getDeviceClass = this.bcc.getMethod("getDeviceClass", new Class[0]);
          this.bsc = Class.forName("android.bluetooth.BluetoothSocket");
          this.bs_connect = this.bsc.getMethod("connect", new Class[0]);
          this.bs_getInputStream = this.bsc.getMethod("getInputStream", new Class[0]);
          this.bs_getOutputStream = this.bsc.getMethod("getOutputStream", new Class[0]);
          this.bs_close = this.bsc.getMethod("close", new Class[0]);
          return;
        }
        catch (ClassNotFoundException localClassNotFoundException)
        {
          ;
        }
        catch (NoSuchMethodException localNoSuchMethodException3)
        {
          ;
        }
      }
      catch (NoSuchMethodException localNoSuchMethodException2)
      {
        ;
      }
    }
    catch (NoSuchMethodException localNoSuchMethodException1)
    {
      ;
    }
  }
  
  public static BTAdapter getDefault(Context var0) throws Exception {
      Object var2;
      label26: {
         Object var6;
         try {
            Class var5 = Class.forName("android.bluetooth.BluetoothAdapter");
            if(Looper.myLooper() == null) {
               Looper.prepare();
            }

            var6 = var5.getMethod("getDefaultAdapter", new Class[0]).invoke((Object)null, new Object[0]);
         } catch (ClassNotFoundException var7) {
            var2 = null;
            break label26;
         } catch (NoSuchMethodException var8) {
            var2 = null;
            break label26;
         }

         var2 = var6;
      }

      BTAdapterImpl20 var3 = null;
      if(var2 != null) {
         BTAdapterImpl20 var10000 = new BTAdapterImpl20(var2);
         var3 = var10000;
      }
      return var3;
   }
  
  
  boolean createBond(String paramString)
    throws Exception
  {
    return ((Boolean)this.bd_createBond.invoke(this.ba_getRemoteDevice.invoke(this.ba, new Object[] { paramString }), new Object[0])).booleanValue();
  }
  
  BTSocket createInsecureRfcommSocket(String paramString, int paramInt)
    throws Exception
  {
    Method localMethod = this.bd_createInsecureRfcommSocket;
    Object localObject = this.ba_getRemoteDevice.invoke(this.ba, new Object[] { paramString });
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Integer.valueOf(paramInt);
    return new SocketImpl(localMethod.invoke(localObject, arrayOfObject));
  }
  
  BTSocket createInsecureRfcommSocketToServiceRecord(String paramString, UUID paramUUID)
    throws Exception
  {
    Object localObject = this.ba_getRemoteDevice.invoke(this.ba, new Object[] { paramString });
    if (this.bd_getServiceChannel != null) {
      try
      {
        Method localMethod1 = this.bd_getServiceChannel;
        Object[] arrayOfObject1 = new Object[1];
        arrayOfObject1[0] = Class.forName("android.os.ParcelUuid").getConstructor(new Class[] { UUID.class }).newInstance(new Object[] { paramUUID });
        int i = ((Integer)localMethod1.invoke(localObject, arrayOfObject1)).intValue();
        if (i > 0)
        {
          Method localMethod2 = this.bd_createInsecureRfcommSocket;
          Object[] arrayOfObject2 = new Object[1];
          arrayOfObject2[0] = Integer.valueOf(i);
          SocketImpl localSocketImpl = new SocketImpl(localMethod2.invoke(localObject, arrayOfObject2));
          return localSocketImpl;
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        App.reportThrowable(localException);
      }
    }
    if (this.bd_createInsecureRfcommSocketToServiceRecord == null) {
      return null;
    }
    return new SocketImpl(this.bd_createInsecureRfcommSocketToServiceRecord.invoke(localObject, new Object[] { paramUUID }));
  }
  
  BTSocket createRfcommSocket(String paramString, int paramInt)
    throws Exception
  {
    Method localMethod = this.bd_createRfcommSocket;
    Object localObject = this.ba_getRemoteDevice.invoke(this.ba, new Object[] { paramString });
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Integer.valueOf(paramInt);
    return new SocketImpl(localMethod.invoke(localObject, arrayOfObject));
  }
  
  BTSocket createRfcommSocketToServiceRecord(String paramString, UUID paramUUID)
    throws Exception
  {
    Object localObject = this.ba_getRemoteDevice.invoke(this.ba, new Object[] { paramString });
    if (this.bd_getServiceChannel != null) {
      try
      {
        Method localMethod1 = this.bd_getServiceChannel;
        Object[] arrayOfObject1 = new Object[1];
        arrayOfObject1[0] = Class.forName("android.os.ParcelUuid").getConstructor(new Class[] { UUID.class }).newInstance(new Object[] { paramUUID });
        int i = ((Integer)localMethod1.invoke(localObject, arrayOfObject1)).intValue();
        if (i > 0)
        {
          Method localMethod2 = this.bd_createRfcommSocket;
          Object[] arrayOfObject2 = new Object[1];
          arrayOfObject2[0] = Integer.valueOf(i);
          SocketImpl localSocketImpl = new SocketImpl(localMethod2.invoke(localObject, arrayOfObject2));
          return localSocketImpl;
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        App.reportThrowable(localException);
      }
    }
    return new SocketImpl(this.bd_createRfcommSocketToServiceRecord.invoke(localObject, new Object[] { paramUUID }));
  }
  
  public void doCancelDiscovery()
    throws Exception
  {
    this.ba_cancelDiscovery.invoke(this.ba, new Object[0]);
  }
  
  public void doStartDiscovery()
    throws Exception
  {
    this.ba_startDiscovery.invoke(this.ba, new Object[0]);
  }
  
  boolean getBondState(String paramString)
    throws Exception
  {
    return this.bd_BOND_BONDED.get(null).equals(this.bd_getBondState.invoke(this.ba_getRemoteDevice.invoke(this.ba, new Object[] { paramString }), new Object[0]));
  }
  
  public String getBondStateChangedIntentAction()
  {
    return "android.bluetooth.device.action.BOND_STATE_CHANGED";
  }
  
  public IntentFilter getDiscoveryIntentFilter()
  {
    IntentFilter localIntentFilter = new IntentFilter();
    localIntentFilter.addAction("android.bluetooth.device.action.FOUND");
    localIntentFilter.addAction("android.bluetooth.device.action.CLASS_CHANGED");
    localIntentFilter.addAction("android.bluetooth.device.action.NAME_CHANGED");
    localIntentFilter.addAction("android.bluetooth.device.action.ALIAS_CHANGED");
    return localIntentFilter;
  }
  
  public BTDevice getRemoteDevice(String paramString)
    throws Exception
  {
    Object localObject1 = this.bdc.cast(this.ba_getRemoteDevice.invoke(this.ba, new Object[] { paramString }));
    String str = (String)this.bd_getName.invoke(localObject1, new Object[0]);
    if (((str == null) || ("".equals(str))) && (this.bd_getAliasName != null)) {
      str = (String)this.bd_getAliasName.invoke(localObject1, new Object[0]);
    }
    Object localObject2 = this.bcc.cast(this.bd_getBluetoothClass.invoke(localObject1, new Object[0]));
    if (localObject2 != null) {}
    for (Integer localInteger = (Integer)this.bc_getDeviceClass.invoke(localObject2, new Object[0]);; localInteger = null) {
      return new BTDevice(this, paramString, str, localInteger);
    }
  }
  
  public boolean isDiscovering()
    throws Exception
  {
    return ((Boolean)this.ba_isDiscovering.invoke(this.ba, new Object[0])).booleanValue();
  }
  
  public boolean isEnabled()
    throws Exception
  {
    return (this.ba != null) && (((Boolean)this.ba_isEnabled.invoke(this.ba, new Object[0])).booleanValue());
  }
  
  public BTDevice parseDiscoveryIntentResult(Intent paramIntent)
    throws Exception
  {
    BTDevice localBTDevice = null;
    if (paramIntent != null)
    {
      Object localObject1 = this.bdc.cast(paramIntent.getParcelableExtra("android.bluetooth.device.extra.DEVICE"));
      localBTDevice = null;
      if (localObject1 != null)
      {
        String str1 = (String)this.bd_getAddress.invoke(localObject1, new Object[0]);
        String str2 = paramIntent.getStringExtra("android.bluetooth.device.extra.NAME");
        if ((str2 == null) || ("".equals(str2))) {
          str2 = (String)this.bd_getName.invoke(localObject1, new Object[0]);
        }
        if (((str2 == null) || ("".equals(str2))) && (this.bd_getAliasName != null)) {
          str2 = (String)this.bd_getAliasName.invoke(localObject1, new Object[0]);
        }
        Object localObject2 = this.bcc.cast(paramIntent.getParcelableExtra("android.bluetooth.device.extra.CLASS"));
        if (localObject2 == null) {
          localObject2 = this.bcc.cast(this.bd_getBluetoothClass.invoke(localObject1, new Object[0]));
        }
        Integer localInteger = null;
        if (localObject2 != null) {
          localInteger = (Integer)this.bc_getDeviceClass.invoke(localObject2, new Object[0]);
        }
        localBTDevice = new BTDevice(this, str1, str2, localInteger);
      }
    }
    return localBTDevice;
  }
  
  class SocketImpl
    extends BTSocket
  {
    Object sk;
    
    SocketImpl(Object paramObject)
      throws Exception
    {
      this.sk = paramObject;
    }
    
    protected boolean connect()
      throws Exception
    {
      BTAdapterImpl20.this.bs_connect.invoke(this.sk, new Object[0]);
      return true;
    }
    
    public void destroy()
      throws Exception
    {
      BTAdapterImpl20.this.bs_close.invoke(this.sk, new Object[0]);
    }
    
    public InputStream getInputStream()
      throws Exception
    {
      return (InputStream)BTAdapterImpl20.this.bs_getInputStream.invoke(this.sk, new Object[0]);
    }
    
    public OutputStream getOutputStream()
      throws Exception
    {
      return (OutputStream)BTAdapterImpl20.this.bs_getOutputStream.invoke(this.sk, new Object[0]);
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.bt.BTAdapterImpl20
 * JD-Core Version:    0.7.0.1
 */